package com.ailot.cloud.mall.controller;

import com.ailot.cloud.base.common.dto.Result;
import com.ailot.cloud.base.log.annotation.Oplog;
import com.ailot.cloud.mall.entity.EnsureService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import com.ailot.cloud.mall.entity.FreightTemplate;
import com.ailot.cloud.mall.service.FreightTemplateService;

/**
 * 运费模板
 * @Author ailot
 * @create 2024-11-14
 */

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/freighttemplate")
public class FreightTemplateController {

    private final FreightTemplateService freightTemplateService;

    /**
     *   分页
     */
    @GetMapping("/page")
    public Page<FreightTemplate> getFreightTemplatePage(Page<FreightTemplate> page, FreightTemplate freightTemplate) {
        return freightTemplateService.page(page, Wrappers.query(freightTemplate));
    }

    /**
     * 新增
     */
    @Oplog("新增")
    @PostMapping
    public Boolean save(@Valid @RequestBody FreightTemplate freightTemplate) {
        return freightTemplateService.save(freightTemplate);
    }

    /**
     * 修改
     */
    @Oplog("修改")
    @PutMapping
    public Boolean update(@Valid @RequestBody FreightTemplate freightTemplate) {
        return freightTemplateService.updateById(freightTemplate);
    }

    /**
     *  删除
     */
    @Oplog("删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        return Result.success(freightTemplateService.removeById(id));
    }

    @GetMapping("/list")
    public List<FreightTemplate> list() {
        return freightTemplateService.list();
    }

}